package com.hhd.pdf.components.table;

import com.itextpdf.text.pdf.PdfPCell;
import lombok.Getter;
import lombok.Setter;
import org.dom4j.Attribute;
import org.dom4j.Element;

@Getter
@Setter
public class TdVo {
    private final Element td;

    public TdVo(Element td) {
        this.td = td;
    }

    public int getColSpan() {
        try {
            Attribute colSpan = td.attribute("colSpan");
            return Integer.parseInt(colSpan.getValue());
        } catch (Exception e) {
            return 1;
        }
    }

    public int getAlign() {
        try {
            Attribute align = td.attribute("align");
            if (align.getText().equals("left")) {
                return PdfPCell.ALIGN_LEFT;
            }
            if (align.getText().equals("right")) {
                return PdfPCell.ALIGN_RIGHT;
            }
        } catch (Exception e) {
            return PdfPCell.ALIGN_CENTER;
        }
        return PdfPCell.ALIGN_CENTER;
    }
}
